package com.yej.aiPolice.presenter

import com.google.gson.Gson
import com.yej.aiPolice.model.beans.User
import com.yej.aiPolice.ui.activity.LoginActivity
import com.yej.aiPolice.util.AiPoliceAPP

class LoginActivityPresenter(val loginActivity: LoginActivity):NetPresenter() {

    //使用手机号码登陆的业务
    fun loginByPhone(phone:String, code:String){
        val loginCall = service.loginByPhone(phone, code)
        loginCall.enqueue(callBack)
    }

    override fun parserJson(json: String?) {
        val user = Gson().fromJson(json,User::class.java)
        if (user != null){
            //缓存到内存中
            AiPoliceAPP.sUser = user
            loginActivity.onLoginSuccess()
        }else{
            loginActivity.onLoginFail()
        }
    }
}